package twoD.hofem;

/**
 * Create the new function g which derivatives from existing function f
 * g(x)=f'(x)
 * 
 * @author White Horse
 * 
 */
public class Derivative implements FunctionRToR {

	private FunctionRToR f_;

	public Derivative(FunctionRToR f) {
		f_ = f;
	}

	/*
	 * Evaluates the derivative at the specified point.
	 * 
	 * @param x point
	 * 
	 * @return 0 because the second derivative of existing function f is not
	 * defined.
	 */
	public double derivativeAt(double x) {
		return 0;
	}

	/*
	 * Returns the breakpoints of a piecewise defined function.
	 * 
	 * @return the breakpoints of existing function f.
	 */
	public double[] getBreakpoints() {
		return f_.getBreakpoints();
	}

	/*
	 * Returns the interval representing the domain on which the function is
	 * defined.
	 * 
	 * @return the domain of existing function f.
	 */
	public Interval getDomain() {
		return f_.getDomain();
	}

	/*
	 * Returns the polynomial degree of this function or -1 if the function is
	 * not a polynomial. If this function is piecewise defined, getP returns the
	 * maximum polynomial degree.
	 * 
	 * @ return the equivalent polynomial degree < "Polynomial of g" =
	 * "Polynomial of f" - 1 > or -1 if the function f is not a polynomial
	 */
	public int getP() {
		if (f_.getP() == -1) {
			return -1;
		}
		return f_.getP() - 1;
	}

	/*
	 * Computes the function value at the specified point
	 * 
	 * @param x point
	 * 
	 * @return the derivative value of existing function f
	 */
	public double valueAt(double x) {

		return f_.derivativeAt(x);
	}

}
